ASPECT_RATIO_627 = {
     '0.26': ([320, 1216], 1), '0.31': ([352, 1120], 1), '0.38': ([384, 1024], 1), '0.43': ([416, 960], 1), 
     '0.52': ([448, 864], 1), '0.58': ([480, 832], 1), '0.67': ([512, 768], 1), '0.74': ([544, 736], 1), 
     '0.86': ([576, 672], 1), '0.95': ([608, 640], 1), '1.05': ([640, 608], 1), '1.17': ([672, 576], 1), 
     '1.29': ([704, 544], 1), '1.35': ([736, 544], 1), '1.50': ([768, 512], 1), '1.67': ([800, 480], 1), 
     '1.73': ([832, 480], 1), '2.00': ([896, 448], 1), '2.31': ([960, 416], 1), '2.58': ([992, 384], 1), 
     '2.75': ([1056, 384], 1), '3.09': ([1088, 352], 1), '3.70': ([1184, 320], 1), '3.80': ([1216, 320], 1), 
     '3.90': ([1248, 320], 1), '4.00': ([1280, 320], 1)
}

ASPECT_RATIO_627_F64 = {
     '0.26': ([320, 1216], 1), '0.38': ([384, 1024], 1), '0.50': ([448, 896], 1), '0.67': ([512, 768], 1), 
     '0.82': ([576, 704], 1),  '1.00': ([640, 640], 1),  '1.22': ([704, 576], 1), '1.50': ([768, 512], 1), 
     '1.86': ([832, 448], 1),  '2.00': ([896, 448], 1),  '2.50': ([960, 384], 1), '2.83': ([1088, 384], 1), 
     '3.60': ([1152, 320], 1), '3.80': ([1216, 320], 1), '4.00': ([1280, 320], 1)}

ASPECT_RATIO_627_F128 = {
     '0.25': ([256, 1024], 1), 
     '0.38': ([384, 1024], 1), 
     '0.43': ([384, 896], 1), 
     '0.57': ([512, 896], 1), 
     '0.67': ([512, 768], 1), 
     '1.00': ([640, 640], 1),  
     '1.50': ([768, 512], 1), 
     '1.75': ([896, 512], 1), 
     '2.33': ([896, 384], 1),  
     '2.67': ([1024, 384], 1), 
     '4.00': ([1024, 256], 1), 
}

ASPECT_RATIO_627_F256 = {
     '0.25': ([256, 1024], 1),
     '0.33': ([256, 768], 1),
     '0.50': ([256, 512], 1),
     '0.67': ([512, 768], 1),
     '1.00': ([512, 512], 1),
     '1.50': ([768, 512], 1),
     '2.00': ([512, 256], 1),
     '3.00': ([768, 256], 1),
     '4.00': ([1024, 256], 1),
}

ASPECT_RATIO_960 = {
     '0.25': ([480, 1920], 1), '0.29': ([512, 1792], 1), '0.32': ([544, 1696], 1), '0.36': ([576, 1600], 1), 
     '0.40': ([608, 1504], 1), '0.49': ([672, 1376], 1), '0.54': ([704, 1312], 1), '0.59': ([736, 1248], 1), 
     '0.69': ([800, 1152], 1), '0.74': ([832, 1120], 1), '0.82': ([864, 1056], 1), '0.88': ([896, 1024], 1), 
     '0.94': ([928, 992], 1), '1.00': ([960, 960], 1), '1.07': ([992, 928], 1), '1.14': ([1024, 896], 1), 
     '1.22': ([1056, 864], 1), '1.31': ([1088, 832], 1), '1.35': ([1120, 832], 1), '1.44': ([1152, 800], 1), 
     '1.70': ([1248, 736], 1), '2.00': ([1344, 672], 1), '2.05': ([1376, 672], 1), '2.47': ([1504, 608], 1), 
     '2.53': ([1536, 608], 1), '2.83': ([1632, 576], 1), '3.06': ([1664, 544], 1), '3.12': ([1696, 544], 1), 
     '3.62': ([1856, 512], 1), '3.93': ([1888, 480], 1), '4.00': ([1920, 480], 1)
}

ASPECT_RATIO_960_F64 = {
     '0.22': ([448, 2048], 1), '0.29': ([512, 1792], 1), '0.36': ([576, 1600], 1), '0.45': ([640, 1408], 1), 
     '0.55': ([704, 1280], 1), '0.63': ([768, 1216], 1), '0.76': ([832, 1088], 1), '0.88': ([896, 1024], 1), 
     '1.00': ([960, 960], 1), '1.14': ([1024, 896], 1), '1.31': ([1088, 832], 1), '1.50': ([1152, 768], 1), 
     '1.58': ([1216, 768], 1), '1.82': ([1280, 704], 1), '1.91': ([1344, 704], 1), '2.20': ([1408, 640], 1), 
     '2.30': ([1472, 640], 1), '2.67': ([1536, 576], 1), '2.89': ([1664, 576], 1), '3.62': ([1856, 512], 1), 
     '3.75': ([1920, 512], 1)}

ASPECT_RATIO_960_F128 = {
     '0.20': ([384, 1920], 1), 
     '0.27': ([512, 1920], 1), 
     '0.33': ([512, 1536], 1),
     '0.42': ([640, 1536], 1), 
     '0.50': ([640, 1280], 1), 
     '0.60': ([768, 1280], 1),
     '0.67': ([768, 1152], 1),
     '0.78': ([896, 1152], 1),
     '1.00': ([1024, 1024], 1), 
     '1.29': ([1152, 896], 1), 
     '1.50': ([1152, 768], 1), 
     '1.67': ([1280, 768], 1), 
     '2.00': ([1280, 640], 1), 
     '2.40': ([1536, 640], 1), 
     '3.00': ([1536, 512], 1), 
     '3.75': ([1920, 512], 1),
     '5.00': ([1920, 384], 1),
}

ASPECT_RATIO_960_F256 = {
    '0.33': ([512, 1536], 1), 
    '0.60': ([768, 1280], 1), 
    '1.00': ([1024, 1024], 1), 
    '1.67': ([1280, 768], 1), 
    '3.00': ([1536, 512], 1), 
}


def get_bucket_config(resolution, scale_factor_spatial):
    if resolution == '480p':
        if scale_factor_spatial == 16 or scale_factor_spatial == 32:
            return ASPECT_RATIO_627
        elif scale_factor_spatial == 64:
            return ASPECT_RATIO_627_F64
        elif scale_factor_spatial == 128:
            return ASPECT_RATIO_627_F128
        elif scale_factor_spatial == 256:
            return ASPECT_RATIO_627_F256
    elif resolution == '720p':
        if scale_factor_spatial == 16 or scale_factor_spatial == 32:
            return ASPECT_RATIO_960
        elif scale_factor_spatial == 64:
            return ASPECT_RATIO_960_F64
        elif scale_factor_spatial == 128:
            return ASPECT_RATIO_960_F128
        elif scale_factor_spatial == 256:
            return ASPECT_RATIO_960_F256
        
    raise ValueError(f"Unsupported resolution '{resolution}' or scale_factor_spatial '{scale_factor_spatial}'")
